package cn.idu.jdbc;


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.SequenceInputStream;
import java.io.StringBufferInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;

public class TestInsert02 {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        try {

            connection = JdbcUtils.getConnector();
            //4. 执行sql的对象，去执行sql
            String sql = "insert into users (id, name, password, email, birthday) values (?,?,?,?,?);";
            statement = connection.prepareStatement(sql);//预编译sql

            statement.setInt(1, 4);
            statement.setString(2, "idou");
            statement.setString(3, "123456");
            statement.setString(4, "idou@163.com");
            statement.setDate(5, new java.sql.Date(new Date().getTime()));

            int lines = statement.executeUpdate();
            if (lines > 0) {
                System.out.println("插入成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.release(connection, statement, resultSet);
        }

    }
}
